import { ImmerReducer, Effect } from 'umi';
import * as api from '@/api';

type Istate = {
  [k in string]: any;
};
type Ipro = {
  namespace: string;
  state: Istate;
  reducers: {
    setlist: ImmerReducer<Istate>;
  };
  effects: {
    getList: Effect;
  };
};
const pro: Ipro = {
  namespace: 'pro', //开启弥明空间
  state: {
    listarr: [],
  },
  reducers: {
    setlist(state, action) {
      console.log(98989);
      console.log(action);
      state.listarr = action.payload;
    },
  },
  effects: {
    *getList({ payload }, { call, put }): any {
      // console.log(3232);
      try {
        console.log(api.getListApi);
        
        let res: any = yield call(api.getListApi);
        console.log(res);

        yield put({
          type: 'setlist',
          payload: res.data.data,
        });
      } catch (error) {
        // console.log(error);
      }
    },
  },
};

export default pro;
